home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MyNewEditText.p < prev    next >
Encoding:
Text File  |  1993-08-11  |  16.7 KB  |  651 lines  |  [TEXT/PJMM]

  1. unit MyNewEditText;
  2.  
  3. interface
  4.  
  5.     const
  6.         paste_to_big = -20;
  7.  
  8.     type
  9.         EditObject = object
  10.                 window: dialogPtr;
  11.                 view_item: integer;
  12.                 view_rect: rect;
  13.                 vcontrol, hcontrol: ControlHandle;
  14.                 te: TEHandle;
  15.                 has_grow: boolean; { hasgrow -> leave room for grow icon }
  16.                 readonly: boolean;
  17.                 undotext: handle;
  18.                 undostart, undoend, undoselstart, undoselend: integer;
  19.                 undoopen: boolean;
  20.                 modified: boolean;
  21.                 procedure Create (dlg: dialogPtr; item, width: integer; vscroll, hscroll, hasgrow, static: boolean);
  22.                 procedure Destroy;
  23.                 procedure Failed (oe: OSErr);
  24.                 procedure InsertText (h: handle);
  25.                 procedure Resize;
  26.                 procedure Draw;
  27.                 procedure DoItemWhere (er: eventRecord; item: integer);
  28.                 procedure DoIdle;
  29.                 procedure DoKey (modifiers: integer; ch: integer);
  30.                 procedure DoActivateDeactivate (activate: boolean);
  31.                 procedure Click (where: point; extend: boolean);
  32.                 procedure Adjust;
  33.                 procedure SetupActions;
  34.                 procedure Action (vertical: boolean; part: integer);
  35.                 function EditMenuEnabled: boolean;
  36.                 procedure SetEditMenuItem (item: integer);
  37.                 procedure DoEditMenu (item: integer);
  38.             end;
  39.  
  40. implementation
  41.  
  42.     uses
  43.         Script, MyTypes, MyDialogs;
  44.  
  45.     const
  46.         inHome = 9998;
  47.         inEnd = 9999;
  48.  
  49.     function Pin (a, b, c: longInt): longInt;
  50.     begin
  51.         if b < a then
  52.             Pin := a
  53.         else if b > c then
  54.             Pin := c
  55.         else
  56.             Pin := b;
  57.     end;
  58.  
  59.     procedure EditObject.Failed (oe: OSErr);
  60.     begin
  61.         SysBeep(1);
  62.     end;
  63.  
  64.     procedure EditObject.Create (dlg: dialogPtr; item, width: integer; vscroll, hscroll, hasgrow, static: boolean);
  65.         var
  66.             dr, vr: rect;
  67.             k: integer;
  68.             h: handle;
  69.     begin
  70.         SetPort(dlg);
  71.         window := dlg;
  72.         view_item := item;
  73.         vcontrol := nil;
  74.         has_grow := hasgrow;
  75.         readonly := static;
  76.         if vscroll then begin
  77.             SetRect(dr, 0, 0, 16, 100);
  78.             vcontrol := NewControl(window, dr, '', true, 0, 0, 0, scrollBarProc, 1);
  79.         end;
  80.         hcontrol := nil;
  81.         if hscroll then begin
  82.             SetRect(dr, 0, 0, 100, 16);
  83.             hcontrol := NewControl(window, dr, '', true, 0, 0, 0, scrollBarProc, 0);
  84.         end;
  85.         GetDItemRect(dlg, view_item, dr);
  86.         view_rect := dr;
  87.         vr := dr;
  88.         dr.right := dr.left + width;
  89.         EraseRect(view_rect);
  90.         te := TENew(dr, vr);
  91.         TEAutoView(true, te);
  92.         undotext := NewHandle(0);
  93.         undostart := -1;
  94.         undoopen := false;
  95.         modified := false;
  96.         Resize;
  97.     end;
  98.  
  99.     procedure EditObject.Destroy;
  100.     begin
  101.         TEDispose(te);
  102.         if vcontrol <> nil then
  103.             DisposeControl(vcontrol);
  104.         if hcontrol <> nil then
  105.             DisposeControl(hcontrol);
  106.         DisposHandle(undotext);
  107.         dispose(self);
  108.     end;
  109.  
  110.     procedure EditObject.InsertText (h: handle);
  111.         var
  112.             state: SignedByte;
  113.     begin
  114.         state := HGetState(h);
  115.         HLock(h);
  116.         TEInsert(h^, GetHandleSize(h), te);
  117.         Adjust;
  118.         HSetState(h, state);
  119.     end;
  120.  
  121.     procedure AdjustTE (te: TEHandle; hc, vc: integer);
  122. {Scroll the TERec around to match up to the potentially updated scrollbar}
  123. {values. This is really useful when the window resizes such that the}
  124. {scrollbars become inactive and the TERec had been previously scrolled.}
  125.         var
  126.             value: INTEGER;
  127.     begin
  128.         with te^^ do
  129.             TEScroll((viewRect.left - destRect.left) - hc, (viewRect.top - destRect.top) - (vc * lineHeight), te);
  130.     end; {AdjustTE}
  131.  
  132.     function AdjustHV (isVert: BOOLEAN; control: ControlHandle; te: TEHandle; canRedraw: BOOLEAN): integer;
  133. {Calculate the new control maximum value and current value, whether it is the horizontal or}
  134. {vertical scrollbar. The vertical max is calculated by comparing the number of lines to the}
  135. {vertical size of the viewRect. The horizontal max is calculated by comparing the maximum document}
  136. {width to the width of the viewRect. The current values are set by comparing the offset between}
  137. {the view and destination rects. If necessary and we canRedraw, have the control be re-drawn by}
  138. {calling ShowControl.}
  139.         var
  140.             value, lines, max: INTEGER;
  141.             oldValue, oldMax: INTEGER;
  142.             cliprgn: RgnHandle;
  143.             r: rect;
  144.     begin
  145.         if control = nil then begin
  146.             value := 0;
  147.         end
  148.         else begin
  149.             oldValue := GetCtlValue(control);
  150.             oldMax := GetCtlMax(control);
  151.             with te^^ do begin
  152.                 if isVert then begin
  153.                     lines := nLines;
  154.         {since nLines isn’t right if the last character is a return, check for that case}
  155.                     if (teLength > 0) & (Ptr(ORD(hText^) + teLength - 1)^ = 13) then
  156.                         lines := lines + 1;
  157.                     max := lines - ((viewRect.bottom - viewRect.top) div lineHeight);
  158.                     if max < 0 then
  159.                         max := 0;            {check for negative values}
  160.                     value := (viewRect.top - destRect.top) div lineHeight
  161.                 end
  162.                 else begin
  163.                     max := destRect.right - destRect.left - (viewRect.right - viewRect.left);
  164.                     if max < 0 then
  165.                         max := 0;            {check for negative values}
  166.                     value := viewRect.left - destRect.left;
  167.                 end;
  168.                 value := Pin(0, value, max);
  169.             end;
  170.             SetCtlMax(control, max);
  171.             SetCtlValue(control, value);
  172.             if canRedraw and ((max <> oldMax) or (value <> oldValue)) then
  173.                 ShowControl(control);            {check to see if the control can be re-drawn}
  174.         end;
  175.         AdjustHV := value;
  176.     end; {AdjustHV}
  177.  
  178.     procedure EditObject.Adjust;
  179.         var
  180.             hc, vc: integer;
  181.     begin
  182.         vc := AdjustHV(true, vcontrol, te, false);
  183.         hc := AdjustHV(false, hcontrol, te, false);
  184.         AdjustTE(te, hc, vc);
  185.     end; {AdjustScrollValues}
  186.  
  187.     procedure EditObject.Resize;
  188.         const
  189.             invis = 0;
  190.             vis = 255;
  191.             inset = 3;
  192.         var
  193.             dr, vr: rect;
  194.             pt: point;
  195.             k: integer;
  196.             h: handle;
  197.             wd, ht: integer;
  198.             hc, vc: integer;
  199.     begin
  200.         SetPort(window);
  201.         EraseRect(view_rect);
  202.         GetDItemRect(window, view_item, vr);
  203.         view_rect := vr;
  204.         InvalRect(vr);
  205.         InsetRect(vr, inset, inset);
  206.         if hcontrol <> nil then
  207.             vr.bottom := vr.bottom - 15;
  208.         if vcontrol <> nil then
  209.             vr.right := vr.right - 15;
  210.         vr.bottom := vr.top + (vr.bottom - vr.top) div te^^.lineHeight * te^^.lineHeight;
  211.  
  212.         pt := vr.topleft;
  213.         SubPt(te^^.viewRect.topleft, pt);
  214.         OffsetRect(te^^.destRect, pt.h, pt.v);
  215.  
  216.         te^^.viewRect := vr;
  217.  
  218.         if vcontrol <> nil then begin
  219.             vcontrol^^.contrlVis := invis;
  220.             MoveControl(vcontrol, view_rect.right - 16, view_rect.top);
  221.             ht := view_rect.bottom - view_rect.top;
  222.             if has_grow then
  223.                 ht := ht - 15;
  224.             SizeControl(vcontrol, 16, ht);
  225.             vc := AdjustHV(true, vcontrol, te, false);
  226.             vcontrol^^.contrlVis := vis;
  227.         end;
  228.         if hcontrol <> nil then begin
  229.             hcontrol^^.contrlVis := invis;
  230.             MoveControl(hcontrol, view_rect.left, view_rect.bottom - 16);
  231.             ht := view_rect.right - view_rect.left;
  232.             if has_grow or (vcontrol <> nil) then
  233.                 ht := ht - 15;
  234.             SizeControl(hcontrol, ht, 16);
  235.             hc := AdjustHV(false, hcontrol, te, false);
  236.             hcontrol^^.contrlVis := vis;
  237.         end;
  238.         AdjustTE(te, hc, vc);
  239.     end;
  240.  
  241.     procedure EditObject.Draw;
  242.         var
  243.             r: rect;
  244.             pt: point;
  245.             k: integer;
  246.             h: handle;
  247.     begin
  248.         GetDItemRect(window, view_item, r);
  249.         EraseRect(r);
  250.         if vcontrol <> nil then begin
  251.             Draw1Control(vcontrol);
  252.         end;
  253.         if hcontrol <> nil then begin
  254.             Draw1Control(hcontrol);
  255.         end;
  256.         EraseRect(te^^.viewRect);
  257.         TEUpdate(te^^.viewRect, te);
  258.     end;
  259.  
  260.     var
  261.         actionTE: TEHandle;
  262.         action_vcontrol, action_hcontrol: ControlHandle;
  263.  
  264. { Common algorithm for pinning the value of a control. It returns the actual amount }
  265. { the value of the control changed. }
  266.     procedure ActionScroll (vertical: boolean; amount: integer);
  267.         var
  268.             value, newvalue, max: integer;
  269.             control: ControlHandle;
  270.     begin
  271.         if vertical then
  272.             control := action_vcontrol
  273.         else
  274.             control := action_hcontrol;
  275.         if control <> nil then begin
  276.             value := GetCtlValue(control);
  277.             max := GetCtlMax(control);
  278.             newvalue := Pin(0, longInt(value) - amount, max);
  279.             SetCtlValue(control, newvalue);
  280.             amount := value - newvalue;   { calculate true change }
  281.             if (amount <> 0) then begin
  282.                 if vertical then begin
  283.                     TEScroll(0, amount * actionTE^^.lineHeight, actionTE);
  284.                 end
  285.                 else begin
  286.                     TEScroll(amount, 0, actionTE);
  287.                 end;
  288.             end;
  289.         end;
  290.     end; { CommonAction  }
  291.  
  292. {$PUSH}
  293. {$D-}
  294.     function MyClickLoop: boolean;
  295.         var
  296.             where: point;
  297.             old_clip: RgnHandle;
  298.     begin
  299.         SetPort(actionTE^^.inPort);
  300.         GetMouse(where);
  301.         old_clip := NewRgn;
  302.         GetClip(old_clip);
  303.         ClipRect(actionTE^^.inPort^.portRect); { need to be able to update the controls }
  304.         if where.v < actionTE^^.viewrect.top then begin
  305.             ActionScroll(true, (actionTE^^.viewrect.top - where.v) div actionTE^^.lineheight + 1);
  306.         end;
  307.         if where.v > actionTE^^.viewrect.bottom then begin
  308.             ActionScroll(true, -((where.v - actionTE^^.viewrect.bottom) div actionTE^^.lineheight + 1));
  309.         end;
  310.         if where.h < actionTE^^.viewrect.left then begin
  311.             ActionScroll(false, actionTE^^.viewrect.left - where.h);
  312.         end;
  313.         if where.h > actionTE^^.viewrect.right then begin
  314.             ActionScroll(false, -actionTE^^.viewrect.right - where.h);
  315.         end;
  316.         SetClip(old_clip);
  317.         DisposeRgn(old_clip);
  318.         MyClickLoop := true;
  319.     end;
  320. {$POP}
  321.  
  322.     procedure EditObject.SetupActions;
  323.     begin
  324.         actionTE := te;
  325.         action_vcontrol := vcontrol;
  326.         action_hcontrol := hcontrol;
  327.     end;
  328.  
  329.     procedure EditObject.Click (where: point; extend: boolean);
  330.     begin
  331.         SetupActions;
  332.         SetPort(window);
  333.         SetClikLoop(@MyClickLoop, te);
  334.         TEClick(where, extend, te);
  335.         if readonly and (te^^.selStart = te^^.selEnd) then begin  { kludge to make the carret go away }
  336.             TEDeactivate(te);
  337.             TEActivate(te);
  338.         end;
  339.     end;
  340.  
  341. { Determines how much to change the value of the vertical scrollbar by and how }
  342. { much to scroll the TE record.}
  343.     procedure ActionProc (control: ControlHandle; part: integer);
  344.         var
  345.             amount: integer;
  346.             vertical: boolean;
  347.     begin
  348.         if control <> nil then begin
  349.             if (part <> 0) then begin
  350.                 vertical := GetCRefCon(control) <> 0;
  351.                 if vertical then begin
  352.                     case part of
  353.                         inUpButton, inDownButton:        { one line  }
  354.                             amount := 1;
  355.                         inPageUp, inPageDown:            { one page  }
  356.                             with actionTE^^, viewRect do
  357.                                 amount := (bottom - top) div lineHeight;
  358.                         inHome, inEnd: 
  359.                             amount := GetCtlMax(control);
  360.                     end;
  361.                 end
  362.                 else begin
  363.                     case part of
  364.                         inUpButton, inDownButton:        { a few pixels }
  365.                             amount := 8;
  366.                         inPageUp, inPageDown:            { a page width }
  367.                             with actionTE^^.viewRect do
  368.                                 amount := (right - left);
  369.                         inHome, inEnd: 
  370.                             amount := GetCtlMax(control);
  371.                     end;
  372.                 end;
  373.                 if ((part = inDownButton) or (part = inPageDown) or (part = inEnd)) then
  374.                     amount := -amount;        { reverse direction for a downer  }
  375.                 ActionScroll(vertical, amount);
  376.             end;
  377.         end;
  378.     end; { ActionProc }
  379.  
  380.     procedure EditObject.Action (vertical: boolean; part: integer);
  381.     begin
  382.         SetupActions;
  383.         if vertical then begin
  384.             ActionProc(vcontrol, part);
  385.         end
  386.         else begin
  387.             ActionProc(hcontrol, part);
  388.         end;
  389.     end;
  390.  
  391.     procedure EditObject.DoItemWhere (er: eventRecord; item: integer);
  392.         var
  393.             control: controlHandle;
  394.             value, part: integer;
  395.             uss, use: integer;
  396.     begin
  397.         uss := te^^.selStart;
  398.         use := te^^.selEnd;
  399.         SetPort(window);
  400.         GlobalToLocal(er.where);
  401.         part := FindControl(er.where, window, control);
  402.         if part = 0 then begin
  403.             if PtInRect(er.where, te^^.viewRect) then
  404.                 Click(er.where, BAND(er.modifiers, shiftKey) <> 0)
  405.         end
  406.         else begin
  407.             if part = inThumb then begin
  408.                 value := GetCtlValue(control);
  409.                 part := TrackControl(control, er.where, nil);
  410.                 if part <> 0 then begin
  411.                     value := value - GetCtlValue(control);
  412.                     if value <> 0 then begin
  413.                         if control = vcontrol then begin
  414.                             TEScroll(0, value * te^^.lineHeight, te);
  415.                         end
  416.                         else begin
  417.                             TEScroll(value, 0, te);
  418.                         end;
  419.                     end;
  420.                 end;
  421.             end
  422.             else begin
  423.                 SetupActions;
  424.                 value := TrackControl(control, er.where, @ActionProc);
  425.             end;
  426.         end;
  427.         if (uss <> te^^.selStart) or (use <> te^^.selEnd) then
  428.             undoopen := false;
  429.     end;
  430.  
  431.     function EditObject.EditMenuEnabled: boolean;
  432.         var
  433.             i: integer;
  434.             offset: longInt;
  435.     begin
  436.         for i := EMundo to EMselectall do
  437.             if i <> EMundo + 1 then
  438.                 SetEditMenuItem(i);
  439.         EditMenuEnabled := false;
  440.         if (te^^.selStart < te^^.selEnd) or (te^^.teLength > 0) then { Select All, Copy }
  441.             EditMenuEnabled := true;
  442.         if not readonly and ((undostart >= 0) or (GetScrap(nil, 'TEXT', offset) > 0)) then { Undo, Paste }
  443.             EditMenuEnabled := true;
  444.     end;
  445.  
  446.     procedure EditObject.SetEditMenuItem (item: integer);
  447.         procedure SetEnable (on: boolean);
  448.         begin
  449.             if on then
  450.                 EnableItem(GetMHandle(M_Edit), item)
  451.             else
  452.                 DisableItem(GetMHandle(M_Edit), item);
  453.         end;
  454.         var
  455.             offset: longInt;
  456.     begin
  457.         case item of
  458.             EMundo: 
  459.                 SetEnable(undostart >= 0);
  460.             EMcut, EMclear: 
  461.                 SetEnable(not readonly and (te^^.selStart < te^^.selEnd));  { Can cut,clear iff there is a selection and its not readonly}
  462.             EMcopy: 
  463.                 SetEnable(te^^.selStart < te^^.selEnd);  { Can copy iff there is a selection }
  464.             EMpaste: 
  465.                 SetEnable(not readonly and (GetScrap(nil, 'TEXT', offset) > 0));        {Paste is enabled for app. windows}
  466.             EMselectall: 
  467.                 SetEnable(te^^.teLength > 0);  { Can select all iff there is something to select }
  468.             otherwise
  469.         end;
  470.     end;
  471.  
  472.     procedure CopyUndoSelection (h: handle; te: TEHandle);
  473.     begin
  474.         SetHandleSize(h, te^^.selEnd - te^^.selStart);
  475.         BlockMove(ptr(longInt(te^^.hText^) + te^^.selStart), h^, te^^.selEnd - te^^.selStart);
  476.     end;
  477.  
  478.     procedure EditObject.DoEditMenu (item: integer);
  479.         var
  480.             oe: OSErr;
  481.             loe: longInt;
  482.             th: handle;
  483.             uss, use: integer;
  484.     begin
  485.         undoopen := false;
  486.         case item of
  487.             EMcopy:  begin
  488.                 TECopy(te);
  489.                 loe := ZeroScrap;
  490.                 oe := TEToScrap;
  491.             end;
  492.             EMselectall:  begin
  493.                 SetPort(window);
  494.                 TESetSelect(0, maxLongInt, te);
  495.             end;
  496.             EMcut:  begin
  497.                 CopyUndoSelection(undotext, te);
  498.                 undoselstart := te^^.selStart;
  499.                 undoselend := te^^.selEnd;
  500.                 undostart := te^^.selStart;
  501.                 undoend := undostart;
  502.                 TECut(te);
  503.                 loe := ZeroScrap;
  504.                 oe := TEToScrap;
  505.                 modified := true;
  506.             end;
  507.             EMclear:  begin
  508.                 CopyUndoSelection(undotext, te);
  509.                 undoselstart := te^^.selStart;
  510.                 undoselend := te^^.selEnd;
  511.                 undostart := te^^.selStart;
  512.                 undoend := undostart;
  513.                 TEDelete(te);
  514.                 modified := true;
  515.             end;
  516.             EMpaste:  begin
  517.                 oe := TEFromScrap;
  518.                 if TEGetScrapLen + (te^^.teLength - (te^^.selEnd - te^^.selStart)) > 32000 then begin
  519.                     Failed(paste_to_big);
  520.                 end
  521.                 else begin
  522.                     CopyUndoSelection(undotext, te);
  523.                     undoselstart := te^^.selStart;
  524.                     undoselend := te^^.selEnd;
  525.                     undostart := te^^.selStart;
  526.                     TEPaste(te);
  527.                     undoend := te^^.selEnd;
  528.                     modified := true;
  529.                 end;
  530.             end;
  531.             EMundo:  begin
  532.                 uss := undoselstart;
  533.                 use := undoselend;
  534.                 undoselstart := te^^.selStart;
  535.                 undoselend := te^^.selEnd;
  536.                 th := NewHandle(undoend - undostart);
  537.                 BlockMove(ptr(longInt(te^^.hText^) + undostart), th^, undoend - undostart); { save undo for redo }
  538.                 TESetSelect(undostart, undoend, te);
  539.                 TEDelete(te);
  540.                 HLock(undotext);
  541.                 TEInsert(undotext^, GetHandleSize(undotext), te);
  542.                 DisposHandle(undotext);
  543.                 undotext := th;
  544.                 undoend := te^^.selEnd;
  545.                 TESetSelect(uss, use, te);
  546.             end;
  547.             otherwise
  548.         end;
  549.     end;
  550.  
  551.     procedure EditObject.DoIdle;
  552.     begin
  553.         if not readonly then
  554.             TEIdle(te);
  555.     end;
  556.  
  557.     procedure EditObject.DoKey (modifiers: integer; ch: integer);
  558.         procedure Doit;
  559.         begin
  560.             TEKey(chr(ch), te);
  561.             Adjust;
  562.         end;
  563.         var
  564.             dk: boolean;
  565.             cmd, opt, shift: boolean;
  566.             start, finish, length: longInt;
  567.     begin
  568.         cmd := BAND(modifiers, cmdKey) <> 0;
  569.         opt := BAND(modifiers, optionKey) <> 0;
  570.         shift := BAND(modifiers, shiftKey) <> 0;
  571.         case ch of
  572.             homeChar: 
  573.                 Action(true, inHome);
  574.             endChar: 
  575.                 Action(true, inEnd);
  576.             pageUpChar: 
  577.                 Action(true, inPageUp);
  578.             pageDownChar: 
  579.                 Action(true, inPageDown);
  580.             rightArrowChar, leftArrowChar, upArrowChar, downArrowChar:  begin
  581.                 finish := te^^.selEnd;
  582.                 start := te^^.selStart;
  583.                 if cmd & opt & (ch = upArrowChar) then begin
  584.                     start := 0;
  585.                     if not shift then
  586.                         finish := 0;
  587.                     TESetSelect(start, finish, te);
  588.                 end
  589.                 else if cmd & opt & (ch = downArrowChar) then begin
  590.                     if not shift then
  591.                         start := maxLongInt;
  592.                     finish := maxLongInt;
  593.                     TESetSelect(start, finish, te);
  594.                 end
  595.                 else begin
  596.                     if shift and (ch = downArrowChar) then
  597.                         TESetSelect(finish, finish, te);
  598.                     TEKey(chr(ch), te);
  599.                     if shift then begin
  600.                         if te^^.selEnd > finish then
  601.                             finish := te^^.selEnd;
  602.                         if te^^.selStart < start then
  603.                             start := te^^.selStart;
  604.                         TESetSelect(start, finish, te);
  605.                     end;
  606.                 end;
  607.                 Adjust;
  608.             end;
  609.             helpChar: 
  610.                 Doit;
  611.             otherwise begin
  612.                 begin
  613.                     if not readonly then begin
  614.                         modified := true;
  615.                         if not undoopen then begin
  616.                             CopyUndoSelection(undotext, te);
  617.                             undoselstart := te^^.selStart;
  618.                             undoselend := te^^.selEnd;
  619.                             undostart := te^^.selStart;
  620.                         end;
  621.                         Doit;
  622.                         undoend := te^^.selEnd;
  623.                         undoopen := true;
  624.                     end
  625.                     else begin
  626.                         SysBeep(1);
  627.                     end; { if }
  628.                 end; { begin }
  629.             end; { otherwise }
  630.         end; { case }
  631.     end; { DoKey }
  632.  
  633.     procedure EditObject.DoActivateDeactivate (activate: boolean);
  634.     begin
  635.         if activate then begin
  636.             TEActivate(te);
  637.         end
  638.         else begin
  639.             TEDeactivate(te);
  640.         end;
  641.     end;
  642.  
  643. end.
  644. SetPort(te^^.inPort);
  645. clipRgn := NewRgn;
  646. GetClip(clipRgn);
  647. SetRect(r, 0, 0, 0, 0);
  648. ClipRect(r);
  649. SetCtlMax(control, max);
  650. SetClip(clipRgn);
  651. DisposeRgn(clipRgn);